#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <string>
#include <sstream>

using namespace std;

unordered_map<string, int> word_to_digit = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

int words_to_number(vector<string>& words) {
    string number_str = "";
    for (int i = 0; i < words.size(); i++) {
        if (word_to_digit.find(words[i]) != word_to_digit.end()) {
            number_str += to_string(word_to_digit[words[i]]);
        } else {
            return -1;
        }
    }
    int number = stoi(number_str);
    if (number >= 100 && number <= 999) {
        return number;
    } else {
        return -1;
    }
}

bool is_prime(int n) {
    if (n <= 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

int closest_prime(int n) {
    if (is_prime(n)) return n;
    int lower = n - 1;
    int upper = n + 1;
    while (true) {
        if (is_prime(lower)) return lower;
        if (is_prime(upper)) return upper;
        lower--;
        upper++;
    }
}

int main() {
    string input_str;
    getline(cin, input_str);

    vector<string> words;
    string word;
    istringstream iss(input_str);
    while (iss >> word) {
        words.push_back(word);
    }

    if (words.size() != 3) {
        cout << "Wrong input" << endl;
        return 0;
    }

    int number = words_to_number(words);
    if (number == -1) {
        cout << "Wrong input" << endl;
    } else {
        cout << closest_prime(number) << endl;
    }

    return 0;
}